
<?php include_once(dirname(__FILE__) . '/../general/head.php'); ?>

<!-- header -->
<?php include_once(dirname(__FILE__) . '/../general/header.php'); ?>

<?php include_once('left.php'); ?>


<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header"><?php echo $title; ?></h1>
        </div>
    </div>
    <?php
    if($resultstatus){
    ?>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-success">
                <div class="panel-heading">
                    <?php echo $resultstatus; ?>
                </div>
            </div>
        </div>
    </div>
    <?php } ?>
    <!-- /.row -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    Thêm tài khoản
                </div>
                <div class="panel-body">
                    <div class="row">
                        <div class="col-lg-6">
                            <form method="post" action="<?php echo site_url(get_folder($loggedUser['title']).'/users/insert_user/'); ?>">
                                <div>
                                    <?php echo validation_errors(); ?>
                                </div>
                                <div class="form-group <?php echo (form_error('username') != '' ? 'has-error' : ''); ?>">
                                    <label>Username (Code)</label>

                                    <input class="form-control normal-width" type="text" name="username" value="" >
                                    <?php print(form_error('username', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group <?php echo (form_error('name') != '' ? 'has-error' : ''); ?>">
                                    <label>Full Name</label>

                                    <input class="form-control normal-width" type="text" name="name" value=""> 
                                    <?php print(form_error('name', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group <?php echo (form_error('user_email') != '' ? 'has-error' : ''); ?>" >
                                    <label>Email</label>

                                    <input class="form-control normal-width" type="text" name="user_email" value=""> 
                                    <?php print(form_error('user_email', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group <?php echo (form_error('starting_day') != '' ? 'has-error' : ''); ?>" >
                                    <label>Strarting day</label>

                                    <input class="form-control normal-width datepicker" id="datepicker" type="text" name="starting_day" value=""> 
                                    <?php print(form_error('starting_day', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group <?php echo (form_error('stopping_day') != '' ? 'has-error' : ''); ?>" >
                                    <label>Stopping day</label>

                                    <input class="form-control normal-width datepicker" type="text" name="stopping_day" value=""> 
                                    <?php print(form_error('stopping_day', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group">
                                        <label>Title</label>
                                        <select name="title" id="title_name" class="form-control normal-width">
                                            <?php foreach ($title_user as $tt) { ?>
                                                    <option  value="<?php echo $tt; ?>"><?php echo $tt; ?></option>
                                            <?php }
                                            ?>
                                        </select>

                                    </div>
                                <div class="form-group" id="RSM">
                                    
                                </div>
                                <div class="form-group" id="SS">
                                    
                                </div>
                                <div class="form-group" id="TL">
                                    
                                </div>
                                <div class="form-group <?php echo (form_error('location') != '' ? 'has-error' : ''); ?>" >
                                    <label>Location</label>

                                    <input class="form-control normal-width" type="text" name="location" autocomplete="off"> 
                                    <?php print(form_error('location', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group <?php echo (form_error('identity_number') != '' ? 'has-error' : ''); ?>" >
                                    <label>Identity No</label>

                                    <input class="form-control normal-width" type="text" name="identity_number" autocomplete="off"> 
                                    <?php print(form_error('identity_number', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group <?php echo (form_error('address') != '' ? 'has-error' : ''); ?>" >
                                    <label>Address</label>

                                    <input class="form-control normal-width" type="text" name="address" autocomplete="off"> 
                                    <?php print(form_error('address', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group <?php echo (form_error('phone') != '' ? 'has-error' : ''); ?>" >
                                    <label>Phone</label>

                                    <input class="form-control normal-width" type="text" name="phone" autocomplete="off"> 
                                    <?php print(form_error('phone', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group">
                                        <label>Status</label>
                                        <select name="status" class="form-control normal-width">
                                            <option  value="active">Active</option> 
                                            <option  value="inactive">Inactive</option>
                                            <option  value="pregnant">Pregnant</option>
                                        </select>

                                </div>
                                <div class="form-group <?php echo (form_error('note') != '' ? 'has-error' : ''); ?>" >
                                    <label>Note</label>

                                    <textarea class="form-control normal-width" type="text" name="note" autocomplete="off">  </textarea>
                                    <?php print(form_error('note', '<label class="control-label" for="inputError">', '</label>')); ?>
                                </div>
                                <div class="form-group">
                                        <label>Group</label>
                                        <select name="user_group" class="form-control normal-width">
                                            <option value=""></option>
                                            <?php foreach ($allgroups as $key => $group) { ?>
                                                        <option  value="<?php echo $group['gid']; ?>"><?php echo $group['group_name']; ?></option>
                                            <?php } ?>
                                        </select>

                                </div>
                                <?php
                                if ($su == "1") {
                                    ?>
                                    <div class="form-group">
                                        <label>Account Type</label>
                                        

                                        <select name="account_type" class="form-control normal-width">
                                        <option <?php
                                        if ($user['su'] == "0") {
                                            echo "selected";
                                        }
                                        ?> value="0">User</option>
                                        <option <?php
                                        if ($user['su'] == "1") {
                                            echo "selected";
                                        }
                                        ?> value="1">Administrator</option>
                                    </select>

                                    </div>
                                    <?php
                                }
                                ?>
                                <br>
                                <input class="btn btn-default" type="submit" value="Thêm mới"> 
                            </form>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>


</div>
<script type="text/javascript" src="<?php echo base_url(); ?>/js/ajax.js" ></script>
<!-- /#page-wrapper -->
<script type="text/javascript">
    $(document).ready(function(){
         $(".datepicker").datepicker({
            format: 'dd-mm-yyyy'
        });
        $('#title_name').change(function(){
            var select = $('#title_name option:selected').val();
            var dataString = 'select=' + select;
            var urlRSM = "<?php echo site_url(get_folder($loggedUser['title']).'/users/getCodeRSM'); ?>";
            var urlSS = "<?php echo site_url(get_folder($loggedUser['title']).'/users/getCodeSS'); ?>";
            var urlTL = "<?php echo site_url(get_folder($loggedUser['title']).'/users/getCodeTL'); ?>";
            if(select=="SS"){
                    getHTMlRSM(urlRSM,dataString);
                    $("#TL").html('');
                    $("#SS").html('');
            } else if (select=="TLGT" || select=="TLMT"){
                getHTMlRSM(urlRSM,dataString);
                getHTMlSS(urlSS,dataString);
                $("#TL").html('');
            } else if (select=="NR"){
                getHTMlRSM(urlRSM,dataString);
                getHTMlSS(urlSS,dataString);
                getHTMlTL(urlTL ,dataString);
            } else {
                 $("#RSM").html('');
                 $("#SS").html('');
                 $("#TL").html('');
            }
        });
        
    });

</script>
<?php include_once(dirname(__FILE__) . '/../sc/footer.php'); ?>